package com.lzm.back.controller;

import com.github.pagehelper.PageInfo;
import com.lzm.back.common.MyResult;
import com.lzm.back.entity.Event;
import com.lzm.back.entity.Notice;
import com.lzm.back.service.NoticeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    private NoticeService noticeService;
    @PostMapping("/add")
    public MyResult addNotice(@RequestBody Notice notice) {
        noticeService.addNotice(notice);
        return MyResult.success();
    }
    @PutMapping("/update")
    public MyResult updateNotice(@RequestBody Notice notice) {
        noticeService.updateNotice(notice);
        return MyResult.success();
    }
    @DeleteMapping("/{id}")
    public MyResult deleteNotice(@PathVariable Long id) {
        noticeService.deleteNotice(id);
        return MyResult.success();
    }
    @DeleteMapping("/batch")
    public MyResult deleteNoticeBaTch(@RequestBody List<Long> ids) {
        for (Long id : ids) {
            noticeService.deleteNotice(id);
        }
        return MyResult.success();
    }
    @GetMapping("/{id}")
    public MyResult selectNoticeById(@PathVariable Long id) {
        return MyResult.success(noticeService.selectNoticeById(id));
    }
    @GetMapping("selectPage")
    public MyResult selectNoticeById(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                     @RequestParam(required = false) String title) {
        PageInfo<Notice> eventPageInfo = noticeService.selectPage(pageNum, pageSize, title);
        return MyResult.success(eventPageInfo);
    }
}
